#pragma once
#include "common.h"

class glfw_callback
{
public:
	virtual void key_callback(int key, int scancode, int action, int mods){};
	virtual void character_callback(unsigned int codepoint){};
	virtual void charmods_callback(unsigned int codepoint, int mods){};
	virtual void cursor_position_callback(double xpos, double ypos){};
	virtual void cursor_enter_callback(int entered){};
	virtual void mouse_button_callback(int button, int action, int mods){};
	virtual void scroll_callback(double xoffset, double yoffset){};
	virtual void drop_callback(int count, const char** paths){};
	virtual void window_size_callback(int width, int height)
	{
		glViewport(0, 0, width, height);
	};
};

class MainWin : public glfw_callback
{
public:
	//typedef bool(*UpdateFun)();

private:
	static MainWin s_mainWin;
	static glfw_callback *s_callback;
	static void window_size_callback(GLFWwindow* window, int width, int height);
	static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
	static void character_callback(GLFWwindow* window, unsigned int codepoint);
	static void charmods_callback(GLFWwindow* window, unsigned int codepoint, int mods);
	static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos);
	static void cursor_enter_callback(GLFWwindow* window, int entered);
	static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
	static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
	static void drop_callback(GLFWwindow* window, int count, const char** paths);
	static void errorCallback(int error, const char* message);

	//UpdateFun m_updateCallback;
	int m_width, m_height;
	double m_mouseX, m_mouseY;
	GLFWwindow *m_glfWnd;
	//std::string m_title;

	MainWin();

public:
	~MainWin();
	static MainWin *GetInstance();

	bool Create(int x, int y, int width, int height, char *title);
	bool Init();
	void Loop();
	//void SetUpdateCallback(UpdateFun fun) { m_updateCallback = fun; }
	void SetCallbackClass(glfw_callback *cb){ s_callback = cb ? cb : this; }
	void RemoveCallback(){ s_callback = this; }
	GLFWwindow* GetHandle(){ return m_glfWnd; }
	int GetWidth(){ return m_width; }
	int GetHeight(){ return m_height; }
	double GetMouseX(){ return m_mouseX; }
	double GetMouseY(){ return m_mouseY; }

};

